home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Best of MacTutor - S…e Code for Volumes 1 to 5
/
The Best of MacTutor - Source Code for Volume 1-5 (Wayzata Technology)(6031)(1990).bin
/
Source Code
/
#43 (Apr 89)
/
XCMDSource Code
/
ADSPCall.p
next >
Wrap
Text File
|
1989-02-13
|
5KB
|
220 lines
(********************************)
(* file: ADSPCall.p *)
(* *)
(* Establish a connection with *)
(* the entity whose name is *)
(* passed as a parameter. *)
(* *)
(* *)
(* params[1] = Name of entity *)
(* params[2] = listen message *)
(* params[3] = number of retries*)
(* params[4] = retry interval *)
(* params[5] = Input buffer siz *)
(* params[6] = Output buffer siz*)
(* *)
(* If already connected, just *)
(* return with noErr *)
(* *)
(* Defaults: *)
(* Input Buffer = 578 *)
(* Output Buffer = 578 *)
(* Retry count = 0 *)
(* Retry interval = 0 *)
(* Out: the Result ::= error *)
(* message, empty if none. *)
(* *)
(* ---------------------------- *)
(* By: Donald Koscheka *)
(* Date: 9-Jan-89 *)
(* All Rights Reserved *)
(* *)
(********************************)
(********************************
Build Sequence
pascal ADSPCall.p -o ADSPCall.p.o
link -m ENTRYPOINT -rt XCMD=1302 -sn Main=ADSPCall∂
ADSPCall.p.o∂
"{libraries}"Interface.o ∂
-o YourStackNameHere
*********************************)
{$R-}
{$S ADSPCall}
UNIT Koscheka;
(*********************************)
INTERFACE
(*********************************)
Uses MemTypes, QuickDraw, OSIntf,
ToolIntf, PackIntf, HyperXCmd,
AppleTalk, ADSP, adspxcmd;
Procedure EntryPoint( paramPtr : XCmdPtr );
(*********************************)
IMPLEMENTATION
(*********************************)
TYPE Str31 = String[31];
PROCEDURE ADSPCall( paramPtr: XCmdPtr ); FORWARD;
Procedure EntryPoint( paramPtr : XCmdPtr );
Begin
ADSPCall( paramPtr );
End;
Procedure ADSPCall( paramPtr : XCmdPtr );
VAR
adsp : ADSPPtr;
error, terr : OSErr;
inBufSiz : Integer;
outBufSiz : Integer;
retry : Integer;
interval : Integer;
eAddr : AddrBlock;
cn : CBPtr;
nbp : NBPPtr;
found : BOOLEAN;
{$I XCmdGlue.inc }
{$I XCMDADSP.inc }
(*********************************)
BEGIN
error := noErr;
found := TRUE; {*** true if already established ***}
WITH paramPtr^ DO
BEGIN
IF (paramCount <> 0) AND (params[1]^ <> NIL) THEN
BEGIN
adsp := ADSPPtr(RetrieveData( 'GLOBALDSPDATA' ));
IF adsp <> NIL THEN
BEGIN
adsp^.checkPoint := RECEIVING;
{**** Before we go too far, let's ***}
{*** look at some of the settings ***}
{*** set the retransmit count ***}
IF params[3] <> NIL THEN
retry := StringToSHort( params[3]^ )
ELSE
retry := 0;
{*** Set the retransmit interval ***}
IF params[4] <> NIL THEN
interval := StringToSHort( params[4]^ )
ELSE
interval := 0;
{*** Set the input buffer size ***}
IF params[5] <> NIL THEN
inBufSiz := StringToSHort( params[5]^ )
ELSE
inBufSiz := ATPBSIZE;
{*** Set the output buffer size ***}
IF params[6] <> NIL THEN
outBufSiz := StringToSHort( params[6]^ )
ELSE
outBufSiz := ATPBSIZE;
{*** (1) Get the entity's address ***}
HLock( Handle( params[1]) );
eAddr := NBPGetAddress( params[1]^ );
HUnlock( Handle( params[1] ) );
{*** Walk through the connection ***}
{*** list to see if the connection ***}
{*** already exists. ***}
IF LongInt(eAddr) <> 0 THEN
BEGIN
cn := adsp^.ends;
found := FALSE;
WHILE (NOT found) DO
IF cn = NIL THEN
found := TRUE
ELSE
IF LongInt( eAddr ) = LongInt( cn^.adr ) THEN
found := TRUE
ELSE
cn := cn^.next;
{*** If the connection already exists ***}
{*** cn will not be NIL so we won't ***}
{*** have to reconnect the two ends, ***}
{*** just fall out, otherwise, try to ***}
{*** make the connection. ***}
IF cn = NIL THEN {*** establish connection ***}
BEGIN
cn^.remName := NBPGetName( eAddr );
cn := DSPCreate(eAddr,inBufSiz,
outBufSiz,retry,
interval,params[2] );
IF cn <> NIL THEN
BEGIN
cn^.remName := NBPGetName( eAddr );
{*** try to discover the name ***}
IF cn^.remName = NIL THEN
BEGIN
nbp := NBPPtr(RetrieveData('GLOBALNBPDATA'));
IF nbp <> NIL THEN
BEGIN
SendCardMessage('DoALookUp');
cn^.remName := NBPGetName( eAddr );
END;
END;
{*** Now "dial for dollars" ***}
WITH cn^.dspPB DO
BEGIN
ioCRefNum := adsp^.dspRefNum;
ccbRefNum := cn^.ccbRef;
csCode := dspOpen;
ocMode := ocRequest;
ioCompletion:= NIL;
remoteCID := 0; {*** don't know this yet ***}
localCID := 0; {*** adsp allocates the id ***}
remoteAddress:= eAddr;
filterAddress.aNet := 0;
filterAddress.aNode := 0;
filterAddress.aSocket:= 0;
SendSeq := 0;
RecvSeq := 0;
SendWindow := 0;
attnSendSeq := 0;
attnRecvSeq := 0;
ocInterval := INTERVAL;
ocMaximum := RETRY;
error := PBControl( @cn^.dspPB, ASYNC );
END;
END;
END;
END; {(LongInt(eAddr) <> 0) }
adsp^.checkPoint := CLOSE_OK;
END;
END;
returnValue := PasToZero( NumToStr( LongInt(error) ) );
END; {*** with paramPtr^ ***}
END;
end.